package com.gz.test;

import javax.swing.*;
import java.awt.*;

public class DrawCircle extends JFrame {

    private Mypanel mp = null;

    public static void main(String[] args) {
        new DrawCircle();
        System.out.println("退出程序");
    }

    public DrawCircle() {
        //初始化面板
        mp = new Mypanel();
        //将面板放到窗口(画框)
        this.add(mp);
        //设置窗口大小
        this.setSize(400,400);
        //点击取消时退出程序(没有这个点击叉，程序会继续运行)
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //可以显示
        this.setVisible(true);
    }
}

class Mypanel extends JPanel {
    public void paint(Graphics g) {
        super.paint(g);
        //测试程序正在运行
        System.out.println("paint 方法被调用~");
        //画出一个圆形
//        g.drawOval(10,10,100,100);

        //画出一个矩形rectangle
//        g.drawRect(10,10,100,100);
        //...
        //设置颜色
        g.setColor(Color.red);
        g.fillOval(50,50,100,100);
    }
}